package jparchess.engine;

public class Evaluator {
	Board board;
	
	public Evaluator(Board board) {
		this.board = board;
	}

	public int getScore() {
		return board.material;
	}
	
	public int countBoardScore() {
		int score = 0;
		for (int i=D.A1; i <= D.H8; i++) {
			switch (board.square[i]) {
				case D.WHITE_PAWN: score+= D.PAWN_VALUE; break;
				case D.WHITE_KNIGHT: score+= D.KNIGHT_VALUE; break;
				case D.WHITE_BISHOP: score+= D.BISHOP_VALUE; break;
				case D.WHITE_ROOK: score+= D.ROOK_VALUE; break;
				case D.WHITE_QUEEN: score+= D.QUEEN_VALUE; break;
				case D.WHITE_KING: score+= D.KING_VALUE; break;
				case D.BLACK_PAWN: score-= D.PAWN_VALUE; break;
				case D.BLACK_KNIGHT: score-= D.KNIGHT_VALUE; break;
				case D.BLACK_BISHOP: score-= D.BISHOP_VALUE; break;
				case D.BLACK_ROOK: score-= D.ROOK_VALUE; break;
				case D.BLACK_QUEEN: score-= D.QUEEN_VALUE; break;
				case D.BLACK_KING: score-= D.KING_VALUE; break;		
			}
		}
		return score;
	}
	
	public int basicEval() {
		int score = 0;
		for (int i=D.A1; i <= D.H8; i++) {
			switch (board.square[i]) {
				case D.WHITE_PAWN: 
					score += D.PAWN_VALUE; // add full pawn unit
					score += D.PAWN_TABLE[i];
					if (i % 8 == 0 || i % 8 == 7) score -= 15; //Rook Pawns are worth 15% less because they can only attack one way
			        break;	
				case D.WHITE_KNIGHT: 
					score += D.KNIGHT_VALUE; // add full pawn unit
					score += D.KNIGHT_TABLE[i];
			        break;	
				case D.WHITE_BISHOP: 
					score += D.BISHOP_VALUE; // add full pawn unit
					score += D.BISHOP_TABLE[i];
			        break;
				case D.WHITE_ROOK: 
					score += D.ROOK_VALUE; // add full pawn unit
					score += D.ROOK_TABLE[i];
			        break;
				case D.WHITE_QUEEN: 
					score += D.QUEEN_VALUE; // add full pawn unit
					score += D.QUEEN_TABLE[i];
			        break;
				case D.WHITE_KING: 
					score += D.KING_VALUE; // add full pawn unit
					score += D.KING_TABLE[i];
			        break;
			        			        
				case D.BLACK_PAWN: 
					score -= D.PAWN_VALUE; // rm full pawn unit
					score -= D.PAWN_TABLE[63-i];
					if ((63-i) % 8 == 0 || (63-i) % 8 == 7) score += 15; //Rook Pawns are worth 15% less because they can only attack one way					
					break;
				case D.BLACK_KNIGHT: 
					score -= D.KNIGHT_VALUE; // add full pawn unit
					score -= D.KNIGHT_TABLE[63-i];
			        break;	
				case D.BLACK_BISHOP: 
					score -= D.BISHOP_VALUE; // add full pawn unit
					score -= D.BISHOP_TABLE[63-i];
			        break;
				case D.BLACK_ROOK: 
					score -= D.ROOK_VALUE; // add full pawn unit
					score -= D.ROOK_TABLE[63-i];
			        break;
				case D.BLACK_QUEEN: 
					score -= D.QUEEN_VALUE; // add full pawn unit
					score -= D.QUEEN_TABLE[63-i];
			        break;
				case D.BLACK_KING: 
					score -= D.KING_VALUE; // add full pawn unit
					score -= D.KING_TABLE[63-i];
			        break;
						
			}
		}
		
		// rochade
		
		return score;
	}
}
